package com.cskaoyan;

import com.cskaoyan.utils.DBCPUtils;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * 创建日期: 2022/08/26 16:27
 *
 * @author ciggar
 */
public class DatasourceDemo {

    public static void main(String[] args) throws SQLException {

        // 1. 从连接池获取连接
        Connection connection = DBCPUtils.getConnection();


        // 2. 创建Statement
        Statement statement = connection.createStatement();


        // 3. 执行SQL语句
        ResultSet resultSet = statement.executeQuery("select * from account");


        // 4. 解析结果集
        while (resultSet.next()) {

            int id = resultSet.getInt("id");
            String name = resultSet.getString("name");
            int money = resultSet.getInt("money");

            System.out.println("id:" + id + ",name:" + name + ",money:" + money);
        }

        // 5. 关闭资源
        resultSet.close();

        statement.close();

        connection.close();


    }
}
